//
//  TimeFlagView.swift
//  SlaughterClient
//
//  Created by 邱仙凯 on 2024/8/5.
//  Copyright © 2024 zwb. All rights reserved.
//

import UIKit
class AddTimeButton:UIButton {
    override func layoutSubviews() {
        super.layoutSubviews()
        titleLabel?.frame = CGRect(x: 0, y: 0, width: self.ks_width - 20, height: self.ks_height)
        imageView?.frame =  CGRect(x: self.ks_width - 20, y: 2, width: 20, height: self.ks_height - 4)
    }
}
class ZyaTimeFlagView:UIView {
   private lazy var statusBg:UIImageView = {
        var v  = UIImageView()
        v.image = UIImage(named: "knifebg")
        return v
    }()
    private lazy var statusLab:UILabel = {
        var v :UILabel = UILabel()
        v.textColor = .red
        v.text = "--"
        v.font = UIFont.boldSystemFont(ofSize: 17)
        return v
    }()
    private lazy var timeLab:UILabel = {
        var v :UILabel = UILabel()
        v.textColor = .red
        v.text = "--"
        v.font = UIFont.boldSystemFont(ofSize: 13)
        v.numberOfLines = 0
        return v
    }()
    private lazy var addtTimeLab:AddTimeButton = {
        var v  = AddTimeButton()
        v.setTitleColor(.red, for: .normal)
        v.setTitle("加时0次", for: .normal)
        v.titleLabel?.font = UIFont.boldSystemFont(ofSize: 13)
        v.setImage(UIImage(named: "jiashi_wenhao"), for: .normal)
        return v
    }()
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = UIColor(kshex: "f0f0f0")
        self.addSubview(statusBg)
        statusBg.snp.makeConstraints { (make) in
            make.left.bottom.top.equalTo(self)
            make.width.equalTo(110)

        }

        statusBg.addSubview(statusLab)
        statusLab.snp.makeConstraints { (make) in
            make.center.equalTo(statusBg)
        }
        self.addSubview(timeLab)
        timeLab.snp.makeConstraints { (make) in
            make.centerY.equalTo(self)
            make.left.equalTo(statusBg.snp.right).offset(5)
        }
        self.addSubview(addtTimeLab)
        addtTimeLab.snp.makeConstraints { (make) in
            make.right.equalTo(self).offset(-5)
            make.centerY.equalTo(self)
            make.width.equalTo(73)
            make.height.equalTo(25)
        }
    
    }
    
    func setTimeFlagInfo(status:String,countDown:String,model:BaseFormModel) {
        self.statusLab.text = status
        if status == "已成交" {
            self.statusLab.textColor = UIColor(kshex: tenderGreen)
            self.timeLab.textColor = UIColor.darkGray
        }
        if status == "进行中" {
            self.statusLab.textColor = .red
            self.timeLab.textColor = UIColor.red
        }
        if status == "未开始" {
            self.statusLab.textColor = UIColor(kshex: tenderBlue)
            self.timeLab.textColor = UIColor.darkGray
        }
        if status == "已结束" {
            self.statusLab.textColor = UIColor.darkGray
            self.timeLab.textColor = UIColor.darkGray

        }
     
        self.timeLab.text  = countDown
        
        if model.zIfOvertime.unwrap == "1" {
            var tstr =  "加时0次"
            if intTran(model.zOvertimedNum) > 0 {
                tstr = "加时\(model.zOvertimedNum.unwrap)次"
            }
            self.addtTimeLab.isHidden = false
            self.addtTimeLab.setTitle(tstr, for: .normal)
            addtTimeLab.addTouchUpInSideAction { _ in
                alertUtil(title: "提示", message: "当最后1分钟第1名发生变动时（含并列），结束时间延长\(model.zOvertimeTime.unwrap)秒，当前已加时\(model.zOvertimedNum.unwrap)次，最多加时\(model.zOvertimeNum.unwrap)次",withCancel: false,operateS:[nameAction(name: "确定", action: { _ in
                    
                })] )
            }
        } else {
            self.addtTimeLab.isHidden = true

        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
